package com.shuyun.demo1;

import io.reactivex.rxjava3.core.BackpressureStrategy;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Observable;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;

/**
 * @description:
 * @author: shuai.chen@shuyun.com
 * @date: 2023/1/13 4:09 PM
 */
public class ConversionDemo {

    @Test
    public void toObservable(){
        Observable<String> observable = Flowable.fromArray("tom", "jerry").toObservable();
    }

    @Test
    public void toFlowable(){
        Observable<String> observable = Observable.create(emitter -> {
            try {
                List<String> list = Arrays.asList("jerry", "tom");
                for (String s : list) {
                    emitter.onNext(s);
                }
                emitter.onComplete();
            } catch (Exception e) {
                emitter.onError(e);
            }
        });
        observable.toFlowable(BackpressureStrategy.MISSING);
    }

}
